//
//  ViewController.m
//  YSUtils
//
//  Created by Apple on 2020/6/1.
//  Copyright © 2020 Apple. All rights reserved.
//

#import "ViewController.h"
#import "UIButton+Position.h"
#import "UIButton+YSKit.h"
#import "UILabel+YSKit.h"
#import "UIImageView+YSKit.h"
#import "UIView+YSKit.h"
#import "EKEventStore+Extension.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [UIButton ys_button]
    .ys_frame(CGRectMake(100, 100, 40, 40))
    .ys_touchSize(CGSizeMake(100, 100))
    .ys_backgroundColor([UIColor redColor])
    .ys_action(self, @selector(buttonAction), UIControlEventTouchUpInside)
    .ys_show(self.view);
    
    [UILabel ys_label]
    .ys_textColor([UIColor blackColor])
    .ys_font([UIFont systemFontOfSize:20])
    .ys_frame(CGRectMake(100, 200, 40, 40))
    .ys_backgroundColor(UIColor.yellowColor)
    .ys_show(self.view);
    
    [UIView ys_view]
    .ys_backgroundColor(UIColor.blackColor)
    .ys_frame(CGRectMake(200, 100, 40, 40))
    .ys_show(self.view);
    
    [UIImageView ys_imageView]
    .ys_backgroundColor(UIColor.blueColor)
    .ys_frame(CGRectMake(200, 200, 40, 40))
    .ys_show(self.view);
}

- (void)buttonAction {
 
    EKEventStore *store = [EKEventStore new];
    
//    NSPredicate * p = [store predicateForEventsWithStartDate:[NSDate dateWithTimeIntervalSince1970:0] endDate:[NSDate dateWithTimeIntervalSinceNow:0] calendars:[store calendarsForEntityType:EKEntityTypeEvent]];
    
    EKEvent *event = [EKEvent eventWithEventStore:store]
    .ys_title(@"标题标题标题标题")
    .ys_notes(@"描述描述秒")
    .ys_location(@"北京市朝阳区高碑店")
    .ys_startDate([NSDate dateWithTimeIntervalSinceNow: 0])
    .ys_endDate([NSDate dateWithTimeIntervalSinceNow:60])
    .ys_calendar([store defaultCalendarForNewEvents])
    .ys_addAlarm([EKAlarm alarmWithRelativeOffset:-60]);
    
    event.URL = [NSURL URLWithString:@"http://www.baidu.com/"];
    
    [store ys_saveEvent:event span:EKSpanThisEvent completion:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"%@", error);
        }
    }];
    
}

@end
